package com.happy3w.ssp.schoolmatehome.repository;

import com.happy3w.ssp.schoolmatehome.entity.ClockInTemplate;
import com.happy3w.ssp.schoolmatehome.service.template.ClockInTemplateSummary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface ClockInTemplateRepository extends JpaRepository<ClockInTemplate, Long> {
    @Query("SELECT new com.happy3w.ssp.schoolmatehome.service.template.ClockInTemplateSummary(t.id, t.name, t.iconName) FROM ClockInTemplate t WHERE t.ownerId = :ownerId")
    List<ClockInTemplateSummary> findByOwnerId(Long ownerId);

    @Query("SELECT new com.happy3w.ssp.schoolmatehome.service.template.ClockInTemplateSummary(t.id, t.name, t.iconName) FROM ClockInTemplate t" +
            " WHERE t.id = :id and t.ownerId = :ownerId")
    Optional<ClockInTemplateSummary> findSummaryById(Long id, Long ownerId);
}